// elem-to-html.ts
import { SlateElement } from '@wangeditor/editor';
import { VariableElement } from '../custom-types';

// 生成 html 的函数
function variableToHtml(elem: SlateElement, childrenHtml: string): string {
  const { value = '', info = '' } = elem as VariableElement;
  const infoStr = encodeURIComponent(JSON.stringify(info));
  return `<span data-w-e-type="variable" data-w-e-is-void data-w-e-is-inline data-value="${value}" data-info="${infoStr}">@${value}</span>`;
}

// 配置
const conf = {
  type: 'variable', // 节点 type ，重要！！！
  elemToHtml: variableToHtml,
};

export default conf;
